﻿@model S4Store.Models.AfterSaleReport.AfterSaleDecoratingReportModel
@{
    Layout = null;

    //公式部分
    List<dynamic> listMonth = new List<dynamic>();
    List<dynamic> listDay = new List<dynamic>();
    string brandname = "";
    for (var dt = Model.BarModel.Start ?? DateTime.Now.AddMonths(-6); dt <= Model.BarModel.End; dt = dt.AddMonths(1))
    {
        var query = Model.MonthConfig.Where(o => o.AddTime.Year == dt.Year && o.AddTime.Month == dt.Month).FirstOrDefault();
        if(query!=null)
        {
            if (string.IsNullOrEmpty(brandname)) 
            {
                brandname = query.CarBrand.Name;
            }
            listMonth.Add(new
            {
                时间 = dt,
                装潢率目标 = query.ZHLMB_DecoratingTargetRate,
                单车装潢额目标 = query.MBDCZHE_DecoratingTargetValumeOnUnitCar
            });
        }else{
            listMonth.Add(new
            {
                时间 = dt,
                装潢率目标 = 0,
                单车装潢额目标 = 0
            });
        }

        var queryDay = Model.DayData.Where(o => o.AddTime.Year == dt.Year && o.AddTime.Month == dt.Month);
        if(queryDay.Count()>0)
        {

            var 销售台次 = queryDay.Sum(o => o.ZHXSTC_DecoratingSaleCarNum);
            var 交车台次 = queryDay.Sum(o => o.JCTC_SaleCarNum);
            var 装潢销售额 = queryDay.Sum(o => o.ZHXSZE_DecoratingSalesTotalVolume);
            
            listDay.Add(new
            {
                时间 = dt,
                
                //J10/G10
                // (已实现装潢销售台次+当日交车台次)  /(本月已交车数+当日交车台次)
                实际装潢率 = 交车台次==0?0:(decimal)销售台次/(decimal)交车台次,
                
                //M9/J9
                //(已实现装潢销售金额+当日装潢销售总额)/(已实现装潢销售台次+当日装潢销售台次)
                实际单车装潢额 = 销售台次 == 0 ? 0 : 装潢销售额/(decimal)销售台次
            });
        }else
        {
            listDay.Add(new
            {
                时间 = dt,
                实际装潢率 = 0,
                实际单车装潢额 = 0
            });
        }
    }
    
    //图标部分
    S4Store.Models.Chart.Line ChartModel = new S4Store.Models.Chart.Line();
    ChartModel.Colors = new List<string> { S4Store.Models.Chart.Color.Green, S4Store.Models.Chart.Color.Blue };
    ChartModel.YAxis = "用品销售率";

    foreach (var item in listMonth.GroupBy(o => o.时间))
    {
        ChartModel.XAxis.Add(item.Key.Year + "-" + item.Key.Month);
    }
    S4Store.Models.Chart.ChartSeries series = new S4Store.Models.Chart.ChartSeries();
    series.Name = "用品销售率目标";
    foreach (var item in listMonth)
    {
        series.Data.Add(item.装潢率目标);
    }
    ChartModel.Serieses.Add(series);
    S4Store.Models.Chart.ChartSeries series1 = new S4Store.Models.Chart.ChartSeries();
    series1.Name = "实际用品销售率";
    foreach (var item in listDay)
    {
        series1.Data.Add(item.实际装潢率*100);
    }
    ChartModel.Serieses.Add(series1);



    S4Store.Models.Chart.Line ChartModel1 = new S4Store.Models.Chart.Line();
    ChartModel1.Colors = new List<string> { S4Store.Models.Chart.Color.Green, S4Store.Models.Chart.Color.Blue };
    ChartModel1.IsRate = false;
    ChartModel1.YAxis = "平均单车用品额";

    foreach (var item in listMonth.GroupBy(o => o.时间))
    {
        ChartModel1.XAxis.Add(item.Key.Year + "-" + item.Key.Month);
    }

    S4Store.Models.Chart.ChartSeries series11 = new S4Store.Models.Chart.ChartSeries();
    series11.Name = "单车装潢额目标";
    foreach (var item in listMonth)
    {
        series11.Data.Add(item.单车装潢额目标);
    }
    ChartModel1.Serieses.Add(series11);

    S4Store.Models.Chart.ChartSeries series12 = new S4Store.Models.Chart.ChartSeries();
    series12.Name = "实际单车装潢额";
    foreach (var item in listDay)
    {
        series12.Data.Add(item.实际单车装潢额);
    }
    ChartModel1.Serieses.Add(series12);

<div style="height:100%; overflow:auto">
@Html.Action("ReportBar", "Common", Model.BarModel)
@*<div class="pagetitle">@(carbrandname)入厂台次过程KPI历史数据查询</div>*@
<div class="pageContent">
	
	<div class="tabs" currentIndex="0" eventType="click">
		<div class="tabsHeader">
			<div class="tabsHeaderContent">
				<ul>
					<li><a href="javascript:;"><span>用品销售率</span></a></li>
					<li><a href="javascript:;"><span>平均单车用品额</span></a></li>
				</ul>
			</div>
		</div>
		<div class="tabsContent" >
			<div>
            @Html.Partial("../Chart/Line", ChartModel)
			</div>
			<div>
            @Html.Partial("../Chart/Line", ChartModel1)
			</div>
		</div>
		<div class="tabsFooter">
			<div class="tabsFooterContent"></div>
		</div>
	</div>
</div>

</div>
}